package com.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.CustomerDAO;
import com.dao.impl.CustomerDAOImpl;

/**
 * Servlet implementation class DeleteCustomerServlet
 */
public class DeleteCustomerServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
				
		String id = request.getParameter("id");
		String resultJson = null;
		
		CustomerDAO cd = new CustomerDAOImpl();
		boolean b = cd.deleteCustomer(Integer.parseInt(id));
		if(b){
			resultJson = "{\"success\":true,\"msg\":\"删除成功！\"}";
		}else{
			resultJson = "{\"success\":false,\"msg\":\"删除失败!\"}";
		}
		response.getWriter().print(resultJson);
		
	}

}
